package com.vitalfit.controller;


import com.vitalfit.enums.ResultEnum;
import com.vitalfit.model.dto.LoginCustomerDTO;
import com.vitalfit.model.dto.RegisterCustomerDTO;
import com.vitalfit.model.vo.LoginCustomerVO;
import com.vitalfit.model.vo.RegisterCustomerVO;
import com.vitalfit.model.vo.ResultVO;
import com.vitalfit.service.serviceImpl.AuthServiceImpl;
import com.vitalfit.utils.ResultVOUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth")
@Validated
public class AuthController {

    private final AuthServiceImpl authServiceImpl;


    @PostMapping("/customer/register")
    public ResultVO<RegisterCustomerVO> registerCustomer(@RequestBody @Valid RegisterCustomerDTO registerCustomerDTO) {
        return ResultVOUtil.buildResult(ResultEnum.REGISTER_SUCCESS,
                authServiceImpl.registerCustomer(registerCustomerDTO));
    }

    @PostMapping("/customer/login")
    public ResultVO<LoginCustomerVO> login(@RequestBody @Valid LoginCustomerDTO loginCustomerDTO) {

        return ResultVOUtil.buildResult(ResultEnum.LOGIN_SUCCESS,
                authServiceImpl.loginCustomer(loginCustomerDTO));
    }

    @PostMapping("/admin/register")
    public ResultVO<RegisterCustomerVO> registerAdmin(@RequestBody @Valid RegisterCustomerDTO registerCustomerDTO) {
        return ResultVOUtil.buildResult(ResultEnum.REGISTER_SUCCESS,
                authServiceImpl.registerAdmin(registerCustomerDTO));
    }

    @PostMapping("/admin/login")
    public ResultVO<LoginCustomerVO> loginAdmin(@RequestBody @Valid LoginCustomerDTO loginCustomerDTO) {

        return ResultVOUtil.buildResult(ResultEnum.LOGIN_SUCCESS,
                authServiceImpl.loginAdmin(loginCustomerDTO));
    }






}

